//
//  PAMobileRegisterView.m
//  PAMobileWallet
//
//  Created by Pay_SMP002 on 13-7-3.
//  Copyright (c) 2013年 平安付. All rights reserved.
//

#import "PAMobileRegisterView.h"
#import "PAMobileRegisterViewController.h"
#import "UIColor+Extend.h"

@implementation PAMobileRegisterView
@synthesize userNameTF;
@synthesize messageCheckTF;
@synthesize userBackImage;
@synthesize passBackImage;

@synthesize checkButton;
@synthesize resultButton;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        cellSize = CGSizeMake(578/2, 100/2);
        

        size = frame.size;
//        CGFloat x, y, w, h;
//        w = 100;
//        h = 30;
//        x = (size.width - w) / 2;
//        y = 150;
        
        resultButton = [UIButton buttonWithType:UIButtonTypeCustom];
        resultButton.frame = CGRectMake((size.width-cellSize.width)/2, 44 + 15+24+10+cellSize.height*2 + 10, cellSize.width, cellSize.height);
        resultButton.backgroundColor = [UIColor clearColor];
        [resultButton setTitle:@"下一步" forState:UIControlStateNormal];
        [resultButton setBackgroundImage:[UIImage imageNamed:@"button_B1.png"] forState:UIControlStateNormal];
        resultButton.titleLabel.textColor = ENABLE_COLOR;
        resultButton.titleLabel.font = [UIFont systemFontOfSize:18.0];

        [resultButton addTarget:self action:@selector(buttonActive:) forControlEvents:UIControlEventTouchUpInside];
        resultButton.tag = 0;
        resultButton.enabled = NO;
        [self addSubview:resultButton];
        
        UILabel * markLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 44 + 15, size.width, 24)];
        markLable.backgroundColor = [UIColor clearColor];
        markLable.text = @"手机号就是您专属的钱转转账号";
        markLable.font = [UIFont systemFontOfSize:14.0];
        markLable.textAlignment = NSTextAlignmentCenter;
        markLable.textColor = [UIColor colorWithHexString:@"#abb0b6"];
        [self addSubview:markLable];
        
        NSMutableArray * imageArray = [[NSMutableArray alloc] initWithObjects:@"register_phonenumTF.png",@"register_checkTF.png", nil];
        for (int i = 0; i < 2; i++)
        {
            UIImageView * backImage = [[UIImageView alloc] initWithFrame:CGRectMake((size.width - cellSize.width)/2, 44 + 15+24+10+cellSize.height*i, cellSize.width, cellSize.height)];
            backImage.backgroundColor = [UIColor clearColor];
            backImage.image = [UIImage imageNamed:[imageArray objectAtIndex:i]];
            [self addSubview:backImage];
        }
    }
    
    userBackImage = [[UIImageView alloc] initWithFrame:CGRectMake((size.width - cellSize.width)/2, 44 + 15+24+10, cellSize.width, cellSize.height)];
    userBackImage.image = [UIImage imageNamed:@"login_account.png"];
    userBackImage.backgroundColor = [UIColor clearColor];
    [self addSubview:userBackImage];

    UIImageView *accountIconIV = [[UIImageView alloc] initWithFrame:CGRectMake(20, (100-61)/4, 40/2, 61/2)];
    accountIconIV.image = [UIImage imageNamed:@"register_icon_phone.png"];
    [userBackImage addSubview:accountIconIV];

    userNameTF = [[UITextField alloc] initWithFrame:CGRectMake((size.width - cellSize.width)/2+60, 44 + 15+24+10, cellSize.width-60, cellSize.height)];
    userNameTF.backgroundColor = [UIColor clearColor];
    [userNameTF setBorderStyle:UITextBorderStyleNone]; //外框类型
    userNameTF.keyboardType = UIKeyboardTypeNumberPad;
    userNameTF.placeholder = @"您的手机号"; //默认显示的字
    userNameTF.secureTextEntry = NO; //密码
    userNameTF.delegate = self;
    userNameTF.contentHorizontalAlignment = NSTextAlignmentCenter;
    userNameTF.contentVerticalAlignment = NSTextAlignmentLeft;
    userNameTF.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
    [userNameTF setTextColor:[UIColor colorWithHexString:@"#ACB086"]];
    [self addSubview:userNameTF];

    passBackImage = [[UIImageView alloc] initWithFrame:CGRectMake((size.width - cellSize.width)/2, 44 + 15+24+10+cellSize.height, cellSize.width, cellSize.height)];
    passBackImage.image = [UIImage imageNamed:@"login_password.png"];
    passBackImage.backgroundColor = [UIColor clearColor];
    [self addSubview:passBackImage];
    
    UIImageView *passIconIV = [[UIImageView alloc] initWithFrame:CGRectMake(20, (100-36)/4, 48/2, 36/2)];
    passIconIV.image = [UIImage imageNamed:@"register_icon_check.png"];
    [passBackImage addSubview:passIconIV];

    messageCheckTF = [[UITextField alloc] initWithFrame:CGRectMake((size.width - cellSize.width)/2+60, 44 + 15+24+10+cellSize.height, cellSize.width-60-110-10, cellSize.height)];
    messageCheckTF.backgroundColor = [UIColor clearColor];
    [messageCheckTF setBorderStyle:UITextBorderStyleNone]; //外框类型
    messageCheckTF.keyboardType = UIKeyboardTypeNumberPad;
    messageCheckTF.placeholder = @"验证码"; //默认显示的字
    messageCheckTF.secureTextEntry = NO; //密码
    messageCheckTF.delegate = self;
    messageCheckTF.contentHorizontalAlignment = NSTextAlignmentCenter;
    messageCheckTF.contentVerticalAlignment = NSTextAlignmentLeft;
    messageCheckTF.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
    [messageCheckTF setTextColor:[UIColor colorWithHexString:@"#ACB086"]];
    [self addSubview:messageCheckTF];

    checkButton = [UIButton buttonWithType:UIButtonTypeCustom];
    checkButton.frame = CGRectMake(size.width - (size.width-cellSize.width)/2 - 110 -3,44 + 15+24+10+cellSize.height + 5, 110, 39);
    checkButton.backgroundColor = [UIColor clearColor];
    [checkButton setTitle:@"获取验证码" forState:UIControlStateNormal];
    [checkButton setBackgroundImage:[UIImage imageNamed:@"card_check4.png"] forState:UIControlStateNormal];
    [checkButton setTintColor:ENABLE_COLOR];
    checkButton.titleLabel.font = [UIFont systemFontOfSize:13.0f];
    [checkButton addTarget:self action:@selector(changeState:) forControlEvents:UIControlEventTouchUpInside];
    checkButton.enabled = NO;
    [self addSubview:checkButton];
    
    return self;
}

- (IBAction)buttonActive:(id)sender
{
    [self.parentController testNext:sender];
}

- (void)changeState:(UIButton *)sender
{
    if (self.parentController && [self.parentController respondsToSelector:@selector(checkMessage:)])
    {
        [self.parentController performSelector:@selector(checkMessage:) withObject:sender];
    }
}


@end
